package com.cloud.admin.service.impl;

import com.cloud.admin.model.entity.MType;
import com.cloud.admin.mapper.MTypeMapper;
import com.cloud.admin.service.MTypeService;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.List;

/**
 * 影视分类
 *
 * @author douhaichao code generator
 * @date 2022-09-29 20:14:30
 */
@Service
@AllArgsConstructor
public class MTypeServiceImpl extends ServiceImpl<MTypeMapper, MType> implements MTypeService {

    /**
   * 根据对象属性查找满足条件的第一条数据     *      * @return
   */
    @Override
    public MType selectOne(MType req) {
        QueryWrapper queryWrapper = new QueryWrapper<MType>();
        queryWrapper.setEntity(req);
        return baseMapper.selectOne(queryWrapper);
    }

    /**
     * 根据条件查询所有
     */
    @Override
    public List<MType> selectAll(MType req) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.setEntity(req);
        return baseMapper.selectList(queryWrapper);
    }

    /**
     * 根据对象查询所有分页数据(精确查询)     *      * @return
     */
    @Override
    public IPage<MType> selectPage(Page page, MType req) {
        IPage<MType> list = baseMapper.selectPage(
                page,
                new QueryWrapper<MType>().setEntity(req));
        return list;
    }

    /**
     * 根据对象查询所有分页数据(模糊查询)     *      * @return
     */
    @Override
    public IPage<MType> selectPageByLike(Page page, MType req) {
        QueryWrapper queryWrapper = new QueryWrapper();
        
                                        if (null !=req.getId()) {
                    queryWrapper.eq("id" , req.getId());
                }
                    
                            if (!StrUtil.isEmpty(req.getTypeName())) {
                    queryWrapper.like("type_name" , req.getTypeName());
                }
                                
                                        if (null !=req.getSort()) {
                    queryWrapper.eq("sort" , req.getSort());
                }
                    
                                        if (null !=req.getIsDel()) {
                    queryWrapper.eq("is_del" , req.getIsDel());
                }
                    
                                        if (null !=req.getCreateTime()) {
                    queryWrapper.eq("create_time" , req.getCreateTime());
                }
                    
                                        if (null !=req.getUpdateTime()) {
                    queryWrapper.eq("update_time" , req.getUpdateTime());
                }
                            IPage<MType> list = baseMapper.selectPage(page, queryWrapper);
        return list;
    }

    /**
     * 根据条件统计数据量     *      * @return
     */
    @Override
    public int count(MType req) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.setEntity(req);
        return baseMapper.selectCount(queryWrapper);
    }
}
